
module.exports = async (ctx, next) => {
    const no = ""+ctx.params.no;
    const regex = new RegExp(no + "$");
    const devices = await strapi.services.device.fetchAll({no:{$regex:regex }});
    if(devices.length===0) return  ctx.notFound();
    const tasks = await strapi.services.task.fetchAll({device:devices[0].id,_limit:1,_sort:'createdAt:ASC'});
    if(!tasks[0]){
        return ctx.notFound();
    }else{
        ctx.params._id= tasks[0].id;
    }
    await next();
};
